The NHibernate designer can create migrations for you. Migrations are created as source code which you can edit to reflect additional actions, conditional logic and overridden behaviour. Your model will give rise to a sequence of migrations as it evolves over time. Migrations are collected together in a migrations project separate from your application and model code.
Selecting the Migrations Project
Because migrations are created as C# or Visual Basic source code, they are stored in a Visual Studio project. You need to specify on your model which project it should store its migrations in.
To do this:
- Open your model, select the Migrations menu and choose Set Migrations Project.
- NHibernate Designer lists the existing projects in your solution.
- Choose a project and click OK, or click the New Project button.
- If you create a new project, NHibernate Designer prompts for the project file. Create a new folder and enter the desired project file name.
Creating a Migration
To create a migration, select the Migrations menu and choose Create Migration.
NHibernate displays the actions required in the Up method to migrate the database from the last migration to the current model design, and the actions required in the Down method to reverse the process. You can de-select any actions that you don’t want generated for you.
Enter a migration name and optionally a description. The migration name will be the name of the generated class and must be a valid class name in the migration project language.
Click OK. NHibernate Designer generates and displays the migration class. You can now edit this class if required.